package com.neiquan.weiguan.fragment;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;

import com.neiquan.weiguan.R;
import com.neiquan.weiguan.adapter.OtherAdapter;
import com.neiquan.weiguan.bean.ChannelItem;
import com.neiquan.weiguan.fragment.base.AppBaseFragment;
import com.neiquan.weiguan.fragment.view.MenuFragmentView;
import com.neiquan.weiguan.presenter.ChannelPresenter;

import net.neiquan.applibrary.utils.LogC;
import net.neiquan.applibrary.wight.NoScrollGridView;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 全部栏目
 */
public class MenuFragment extends AppBaseFragment implements AdapterView.OnItemClickListener, MenuFragmentView {

    @InjectView(R.id.gridview_menu)
    NoScrollGridView mGridviewMenu;
    private OtherAdapter otherAdapter;
    private List<ChannelItem> channelItems = new ArrayList<ChannelItem>();
    private ChannelPresenter channelPresenter;

    @Override
    public View initRootView() {
        rootView = LayoutInflater.from(getContext()).inflate(R.layout.fragment_menu, null);
        ButterKnife.inject(this, rootView);
        return rootView;
    }

    @Override
    public void setViews() {
        setTitleTv("栏目选择");
        channelPresenter = new ChannelPresenter(getActivity(), this);
        channelPresenter.getAllChannel();
        mGridviewMenu.setOnItemClickListener(this);
        otherAdapter = new OtherAdapter(getActivity(), channelItems);
        mGridviewMenu.setAdapter(this.otherAdapter);
    }

    @Override
    public void initData() {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent();
        intent.putExtra("data", (ChannelItem) parent.getItemAtPosition(position));
        getActivity().setResult(0, intent);
        getActivity().finish();
    }

    @Override
    public void getMenusList(List<ChannelItem> channelItems) {
        this.channelItems = channelItems;
    }
}
